from neo4j import GraphDatabase

# 导入neo4j官方驱动包
from neo4j import GraphDatabase

# 设置Neo4j数据库的连接地址
uri = "bolt://localhost:7687"
# 设置认证信息（用户名和密码）
auth = ("neo4j", "12345678")
# 创建数据库驱动对象
driver = GraphDatabase.driver(uri, auth=auth)


def query_events(driver):
    with driver.session() as session:
        # 查询今日事件（使用原生函数）
        result = session.run(
            """
            MATCH (e:Event)
            WHERE date(e.time) = date()
            RETURN e.name, e.time
        """
        )
        for record in result:
            print(f"{record['e.name']} at {record['e.time']}")

        # 使用APOC格式化输出
        result = session.run(
            """
            MATCH (e:Event)
            RETURN e.name, 
                   apoc.temporal.format(e.time, 'yyyy-MM-dd HH:mm') AS time
            LIMIT 5
        """
        )
        for record in result:
            print(f"{record['e.name']} at {record['time']}")


query_events(driver)
